// pages/list/list.js
var app = getApp()
import { getCategoryList } from '../../../config/category.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: {},
    info: {
      product: {
        id: '',
        price: '',
        name: '',
        main_img: '',
        time: '',
        unit: '',
        service_category_id: '',
        content: ''
      },
      address: {
        id: '',
        name: '',
        phone: '',
        address: '',
        province_id: '',
        city_id: '',
        district_id: ''
      },
      time: {
        start_at: '',
        end_at: '',
        hours: 1
      },
      cleaner: {
        id: '',
        wx_avatar_url: '',
        real_name: ''
      },
      coupon: {
        id: '',
        price: '',
      },
      remark: '',
      totalPrice: 0,
      textarea: true
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this,
        cid = options.id
    that.initApp(cid)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  initApp: function(cid) {
    let that = this
    wx.showLoading({
      mask: true,
      title: app.globalData.loadText,
    })
    getCategoryList(cid).then(res => {
      that.setData({
        list: res.data.child
      })
      wx.hideLoading()
    }).catch(err => {
      console.log(err)
    })
  },

  /**
   * bind:click
   */
  goProList: function(e) {
    let _this = this,
        product_id = e.currentTarget.id,
        arr1 = ["1", "8", "11", "12", "17", "20", "24"],
        arr2 = ["9", "18", "19", "27", "28", "29", "32"],
        arr4 = ["30"]

    _this.setData({
      'info.product.id': product_id
    })

    if (app.isInArray(arr1, product_id)) {
      wx.navigateTo({
        url: '/pages/product/first/first?info=' + JSON.stringify(_this.data.info),
      })
    } else if (app.isInArray(arr2, product_id)) {
      wx.navigateTo({
        url: '/pages/product/second/second?info=' + JSON.stringify(_this.data.info),
      })
    } else if (app.isInArray(arr4, product_id)) {
      wx.navigateTo({
        url: '/pages/product/third/third?info=' + JSON.stringify(_this.data.info),
      })
    } else {
      wx.navigateTo({
        url: '/pages/product/product?info=' + JSON.stringify(_this.data.info),
      })
    }
  }
})